/*
 * Copyright 2012 Gregor Schauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.schauer.gregor.vienna.example.common.entity;

import javax.persistence.*;

/**
 * @author Gregor Schauer
 */
@MappedSuperclass
public abstract class AbstractAddress {
	@Id
	@GeneratedValue
	@Column(name = "pk")
	protected Long id;
	protected String street;
	protected int postcode;
	protected String city;
	@ManyToOne
	protected Customer customer;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public Integer getPostcode() {
		return postcode;
	}

	public void setPostcode(Integer postcode) {
		this.postcode = postcode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null || getClass() != obj.getClass()) return false;

		AbstractAddress that = (AbstractAddress) obj;

		if (postcode != that.postcode) return false;
		if (!city.equals(that.city)) return false;
		if (customer != null ? !customer.equals(that.customer) : that.customer != null) return false;
		if (!id.equals(that.id)) return false;
		if (!street.equals(that.street)) return false;

		return true;
	}
}
